package wedaex.remote;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import wedaex.remote.handler.GetContentExtractorListHandler;
import wedaex.remote.handler.RegExpExtractHandler;
import wedaex.remote.handler.RemoveContentExtractorHandler;

public abstract class JsonHandler {
	private static Map<String, JsonHandler> handlerMap = new HashMap<String, JsonHandler>();

	static {
		// register handlers here
		handlerMap.put("regExpExtract", new RegExpExtractHandler());
		handlerMap.put("getContentExtractorList", new GetContentExtractorListHandler());
		handlerMap.put("removeContentExtractor", new RemoveContentExtractorHandler());
	}

	public static JsonHandler getInstance(String name) {
		return handlerMap.get(name);
	}
	
	/**
	 * Handle an ajax request and return the JSON response 
	 * @param request
	 * @param response
	 * @return the JSON response
	 */
	public abstract String handle(HttpServletRequest request, HttpServletResponse response) throws Exception;
}
